package com.qianyu.project.web.controller.xz;


import cn.hutool.extra.spring.SpringUtil;
import com.qianyu.project.core.bean.FundEssentialinformation;
import com.qianyu.project.service.IExpendFundPlanService;
import com.qianyu.project.utils.Result;
import com.qianyu.project.utils.ResultTool;
import com.qianyu.project.vo.ExpendFundPlanExtend;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/expendFundPlan")
public class ExpendFundPlanController {

    @Autowired
    private IExpendFundPlanService expendFundPlanService;


    /**
     *
     * @param params
     * @return
     * 资金支出计划列表查询
     */
    @GetMapping("/page")
    public Result getPageList(@RequestParam Map<String, String>  params) {
        return ResultTool.success(expendFundPlanService.getPageList(params));
    }

    /**
     * 得到最大计划编号
     * @return
     */
    @GetMapping("/code")
    public Result getMaxCode() {
        return ResultTool.success(Long.parseLong(expendFundPlanService.getMaxCode()) + 1);
    }


    /**
     *查询支出资金计划基本信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable String id) {
        System.out.println(expendFundPlanService.getById(id));
        return ResultTool.success(expendFundPlanService.getById(id));

    }

    /**
     *
     * @param expendFundPlanExtend
     * @return
     * 资金支出计划保存
     */
    @PostMapping
    public Result save(@RequestBody ExpendFundPlanExtend expendFundPlanExtend) {
        expendFundPlanService.saveWithDetails(expendFundPlanExtend.getExpendFundPlanjbxx(), expendFundPlanExtend.getExpendFundPlanmx());
        return ResultTool.success();
    }



    @DeleteMapping("{id}")
    public Result del(@PathVariable String id){
        expendFundPlanService.del(id);
        return ResultTool.success();
    }


}
